package com.dtw.ditouwang.ui.more;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.BaseExpandableListAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.dtw.ditouwang.R;
import com.dtw.ditouwang.beans.EditorChooseBean;
import com.dtw.ditouwang.models.WebApi;

public class MoreEditorChoooseAdapter extends BaseExpandableListAdapter {
    EditorChooseBean editorChooseBean;

    public MoreEditorChoooseAdapter(EditorChooseBean editorChooseBean){

        this.editorChooseBean = editorChooseBean;
    }

    @Override
    public int getGroupCount() {
        if(editorChooseBean!=null){
            return editorChooseBean.getData().getData().size();
        }
        return 0;
    }

    @Override
    public int getChildrenCount(int groupPosition) {
        if(editorChooseBean!=null){
            return editorChooseBean.getData().getData().get(groupPosition).getData().size();
        }
        return 0;
    }

    @Override
    public Object getGroup(int groupPosition) {
        return editorChooseBean.getData().getData().get(groupPosition);
    }

    @Override
    public Object getChild(int groupPosition, int childPosition) {
        return editorChooseBean.getData().getData().get(groupPosition).getData().get(childPosition);
    }

    @Override
    public long getGroupId(int groupPosition) {
        return groupPosition;
    }

    @Override
    public long getChildId(int groupPosition, int childPosition) {
        return groupPosition*100+childPosition;
    }

    @Override
    public boolean hasStableIds() {
        return true;
    }

    @Override
    public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
        View viewGroup=LayoutInflater.from(parent.getContext()).inflate(R.layout.item_editor_choose_title,parent,false);
        TextView title = viewGroup.findViewById(R.id.text_title);
        title.setText(editorChooseBean.getData().getData().get(groupPosition).getName());
        return viewGroup;
    }

    @Override
    public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
        View viewChild=LayoutInflater.from(parent.getContext()).inflate(R.layout.item_editor_choose_image,parent,false);
        TextView contentText=viewChild.findViewById(R.id.text_content);
        ImageView contentImage = viewChild.findViewById(R.id.image_image);
        contentText.setText(editorChooseBean.getData().getData().get(groupPosition).getData().get(childPosition).getName());
        Glide.with(contentImage).load(WebApi.BaseUrl + editorChooseBean.getData().getData().get(groupPosition).getData().get(childPosition).getBg_img().replace("\\", "/")).into(contentImage);
        return viewChild;
    }

    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return true;
    }
}
